#include "MyGraphic.h"
#include "MyFunction.h"
#include <cairo/cairo.h>
#include <cairo/cairo-win32.h>

#define M_PI 3.14

class MyCairo : public MyGraphic
{
private:
	cairo_t* _context;
public:
	//Constructor
	MyCairo() {
	}
	MyCairo(HDC hdc) {
		cairo_surface_t	*surface = cairo_win32_surface_create(hdc);
		_context = cairo_create(surface);
		
	}
	//Drawing methods
	void DrawLine(char stroke[], float strokeWidth, int x1, int y1, int x2, int y2) {
		cairo_set_source_rgb(_context, MyFunction::Char2Double(stroke[0]), MyFunction::Char2Double(stroke[1]), MyFunction::Char2Double(stroke[2]));
		cairo_move_to(_context, x1, y1);
		cairo_line_to(_context, x2, y2);
		cairo_stroke(_context);
	}
	void DrawRectangle(char stroke[], float strokeWidth, int x, int y, int width, int height) {
		cairo_set_source_rgb(_context, MyFunction::Char2Double(stroke[0]), MyFunction::Char2Double(stroke[1]), MyFunction::Char2Double(stroke[2]));
		cairo_rectangle(_context, x, y, width, height);
		cairo_stroke(_context);
	}
	void DrawEllipse(char stroke[], float strokeWidth, int x, int y, int width, int height) {
		cairo_save (_context);
		cairo_translate (_context, x + width / 2., y + height / 2.);
		cairo_scale (_context, width / 2., height / 2.);
		cairo_arc (_context, 0., 0., 1., 0., 2 * M_PI);
		cairo_restore (_context);
	}
	void FillRectangle(char color[], int x, int y, int width, int height) {
		cairo_set_source_rgb(_context, MyFunction::Char2Double(color[0]), MyFunction::Char2Double(color[1]), MyFunction::Char2Double(color[2]));
	}
	void FillEllipse(char color[], int x, int y, int width, int height) {
		cairo_set_source_rgb(_context, MyFunction::Char2Double(color[0]), MyFunction::Char2Double(color[1]), MyFunction::Char2Double(color[2]));
	}
	//Destructor
	~MyCairo() {
		delete _context;
	}
};